//package com.survival.entity;
public abstract class Character {
    protected String name;//角色名称
    protected int health;//健康值
    protected int hunger;//饥饿值
    protected int thirst;//口渴值
    protected int spirit;//精神值

    //状态自然消耗（每天结束触发，子类可重写调整消耗速率）
    public void consumState(int difficulty){
        //难度越高，消耗越快（1=简单，2=普通，3=困难）
        int hungerConsume = 5 * difficulty;
        int thirstConsume = 8 * difficulty;
        int spiritConsume = 3 * difficulty;

        this.hunger = Math.max(0, this.hunger - hungerConsume);
        this.thirst = Math.max(0, this.thirst - thirstConsume);
        this.spirit = Math.max(0, this.spirit - spiritConsume);

        if(hunger < 20) health = Math.max(0, health - 2 * difficulty);
        if(thirst < 15) thirst = Math.max(0, health - 3 * difficulty);
        if(spirit < 10) spirit = Math.max(0, health - 1 * difficulty);
    }
    //使用物品
    public void useItem(String itemType, int value){
        switch (itemType){
            case "食物":
                this.hunger = Math.min(100, this.hunger + value);
                break;
            case "水":
                this.hunger = Math.min(100, this.hunger + value);
                break;
            case "药品":
                this.hunger = Math.min(100, this.hunger + value);
                break;
            case "精神物品":
                this.hunger = Math.min(100, this.hunger + value);
                break;
        }
        System.out.printf("%s使用了[%s],%s+%d!\n", name, itemType, itemType.equals("食物") ? "饥饿值" : itemType.equals("水") ? "口渴值" : itemType.equals("药品") ? "健康值" : "精神值", value);
    }

    //显示个人状态
    public String showState(){
        return String.format("[%s]\n健康值：%d/100 | 饥饿值：%d/100 | 口渴值：%d/100 | 精神值：%d/100", name, health, hunger, thirst, spirit);
    }
}
